package com.hks360.car_treasure.util;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.hks360.car_treasure.model.Add.User;
import com.hks360.car_treasure.model.BaseModel;
import com.hks360.car_treasure.model.CarLocation;
import com.hks360.car_treasure.model.CarState;
import com.hks360.car_treasure.model.JourneyLocation;
import com.hks360.library.util.CommonUtil;
import com.hks360.third_party_library.util.GsonService;

import java.util.List;

/**
 * GSON解析工具类
 * 将JSON解析成CLASS
 */
public class GsonParseUtil {

    public static BaseModel parseBase(String result) {
        return GsonService.parseJson(result, BaseModel.class);
    }

    public static CarLocation parseCarLocation(String result) {
        return GsonService.parseJson(result,CarLocation.class);
    }

    public static User parseUser(String result) {
        try {
            List<User> list = GsonService.parseJson(result,new TypeToken<List<User>>(){}.getType());
            return list.get(0);
        }catch (Exception e) {
           return GsonService.parseJson(result,User.class);
        }
    }

    public static List<JourneyLocation> parseJourneyLocation(String result) {
        try {
            return GsonService.parseJson(result,new TypeToken<List<JourneyLocation>>(){}.getType());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }



    public static CarState parseCarState(String result) {
        return GsonService.parseJson(result,CarState.class);
    }
}
